<template>
	<view class="pageBox" :style="{paddingTop: statusBarHeight + 44 + 'px',}">
		<view class="topHead flex-between" :style="{top: statusBarHeight + 'px',}">
			<uni-icons type="back" size="24" @click="goBack"></uni-icons>
			<view class="title">
				绑定交易所
			</view>
			<view class="right" @click="onRight">
				已绑定交易所
			</view>
		</view>
		<view class="bourse">
			<uni-data-select :localdata="localdata" v-model="bourse" placeholder="请选择交易所" :clear="false" ></uni-data-select>
			<!-- <uni-combox :candidates="candidates" :border="false" placeholder="请选择交易所" v-model="bourse"></uni-combox> -->
		</view>
		<input type="text" class="ipt" placeholder="请输入账号" v-model="account">

		<button :plain="true" class="btn" @click='addExchange'>绑定</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: "",
				localdata: [],
				bourse: "",
				account: "",
			}
		},
		onLoad() {
			this.statusBarHeight = this.$mySysInfo().top;
		},
		onShow() {
			this.getAllExchange()
		},
		methods: {
			onRight() {
				uni.navigateTo({
					url: '/serviceCenter/bounded'
				})
			},
			getAllExchange() {
				this.$post({
					module: 'Exchange',
					interface: 5000,
					data: {
						type: 1
					}
				}).then(res => {
					// let candidates = [], candidatesId = [];
					// res.forEach(item => {
					// 	candidates.push(item.label)
					// 	candidatesId.push(item.value)
					// })
					this.localdata = res.map(item => ({
						text: item.label,
						value: item.value
					}));
					// this.candidates = candidates;
					// this.candidatesId = candidatesId;
				})
			},
			addExchange() {

				this.$post({
					module: 'User',
					interface: 7000,
					data: {
						exchange_id: this.bourse.toString(),
						account: this.account
					}
				}).then(res => {
					uni.showToast({
						title: '添加成功',
						icon: "none",
						duration: 1500,
					})
					setTimeout(() => {
						this.goBack()
					}, 1000)
				})
			},
			goBack() {
				const pages = getCurrentPages()
				if (pages.length === 1) {
					if (typeof params === 'number') {
						history.go(-params)
					} else {
						history.back()
					}
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			}
		},
	}
</script>

<style scoped lang="scss">
	.pageBox {
		padding: 0 32rpx;
		.topHead {
			background-color: #ffffff;
			height: 88rpx;
			width: 100%;
			padding: 0 32rpx;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 3;
		
			.title {
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
				position: absolute;
				top: 22rpx;
				left: 50%;
				transform: translate(-50%, 0);
			}
		
			.right {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #F2615F;
			}
		}

		.bourse {
			width: 256rpx;
			height: 80rpx;
			background: #f9f9f9;
			border-radius: 16rpx;
			
			/deep/ .uni-stat__select{
				padding: 0;
				
				.uni-stat__actived{
					outline: none;
				}
				
				.uni-select{
					width: 256rpx;
					border: 0;
					box-shadow: none;
					padding: 0 20rpx;
					box-sizing: border-box;
					
					.uni-select__input-text{
						width: 180rpx;
					}
				}
			}

			/deep/.uni-input-input {
				font-size: 32rpx;
			}

			/deep/.uni-combox__input-plac {
				font-size: 32rpx;
			}
		}

		.ipt {
			width: 100%;
			height: 80rpx;
			background: #f9f9f9;
			border-radius: 16rpx;
			margin-top: 28rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #000000;
			line-height: 44rpx;
			padding-left: 16rpx;
		}

		.btn {
			font-size: 36rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #ffffff;
			width: 606rpx;
			height: 104rpx;
			background: #F2615F;
			border-radius: 52rpx;
			border: none;
			padding: 0;
			margin: 236rpx auto 0;
		}
	}
</style>
